#version 110

uniform float lightRadius;
uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;
uniform vec4 LightPosition;
uniform vec3 LightIntensity;

varying vec3 lightDir;
varying vec3 viewDir;



void main()
{
   gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix  * gl_Vertex;

    gl_TexCoord[0] = gl_MultiTexCoord0;


    
   vec3 vertexPos = vec3( ModelMatrix * gl_Vertex);
  


    vec3 n = normalize(gl_NormalMatrix * gl_Normal); 
   
    vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord0.xyz);
    vec3 b = cross(n, t) * gl_MultiTexCoord0.w;
    
    mat3 tbnMatrix = (mat3(t.x, b.x, n.x,
                          t.y, b.y, n.y,
                          t.z, b.z, n.z));


    lightDir = tbnMatrix * LightIntensity;

    viewDir = -vertexPos;
    viewDir = tbnMatrix * viewDir;
}

